<template>
	<view class="huiyuankawanshanpage">
		<view class="header">
			完善考生信息
		</view>
		<view class="header_sub">
			更精准地服务考生，需要您完善信息(我们会严格保密
			您的信息 ，请放心填写
		</view>
		<view class="main">
			<view class="title">
				所在地
			</view>

			<view class="box" @tap.stop="pickerviewtrue">
				<!-- <pick-regions v-if="numbers == 3" class="pickerContent" :defaultRegion="defaultRegionCode"
					@getRegion="handleGetRegion" :CHINA_REGIONS="newJsondata">
					<text class="changecolorN">{{regionName}}</text>
				</pick-regions> -->
				<view class="">
					<text style="color: #333333;" v-for="ele in pickerviewdata"
						:key="ele.code">{{ele.name}}&nbsp;</text> &nbsp;
				</view>

				<image src="https://mcdn.chatgk.com/xcx/static/images/chancePageImg/chancego.png" mode=""></image>
			</view>
		</view>
		<view class="main">
			<view class="title">
				院校
			</view>
			<view class="box" @tap.stop="pickerviewtrue2">
				<!-- <picker class="school" @change="bindPickerChange" :value="index" :range="array"> -->
				<view class="uni-input">{{schoolName}}</view>
				<!-- </picker> -->
				<image src="https://mcdn.chatgk.com/xcx/static/images/chancePageImg/chancego.png" mode=""></image>
			</view>
		</view>
		<view class="main">
			<view class="title">
				班级
			</view>
			<view class="box">
				<input v-model="banji" type="text" placeholder="请点击输入">
			</view>
		</view>

	</view>
	<view class="filexdibu">
		<view class="buttonBox" @tap="posi">
			完成
		</view>
	</view>
	<pickerpopup class="pagefixed" v-if="numbers == 3&&pickerviewishow" :CHINA_REGIONSS="newJsondata"
		@getpicker="getpicker" @pickerviewfalse="pickerviewfalse"></pickerpopup>
	<pickerviewscholl class="pagefixed" v-if="numbers == 3&&pickerviewishow2" :ARR="array" @getpicker="getpicker2"
		@pickerviewfalse="pickerviewfalse2"></pickerviewscholl>

</template>

<script>
	import pickRegions from '@/components/pick-regions/pick-regions.vue'
	import CHINA_REGIONS from '@/components/pick-regions/regions.json'
	import userManager from '@/common/manager/user-manager.js'
	export default {
		components: {
			pickRegions
		},
		data() {
			return {
				province: '请点击选择',
				diquObj: {},
				changecolor: 1,
				defaultRegionCode: '440113',
				userInfo: null,
				showBox: false,
				genderInput: "1",
				userInfoNick: '',
				region: [{
					name: '四川省'
				}, {
					name: '成都市'
				}, {
					name: '成华区'
				}],
				schoolName: '请选择您的学校',
				schoolCode: '',
				banji: '',

				defaultRegion: ['广东省', '广州市', '番禺区'],
				newJsondata: [],
				qiniutoken: '',
				key: '',
				myheadImage: "",

				// picker  
				array: ['中国', '美国', '巴西', '日本'],
				linshiSchool: [],
				index: 0,
				changeImage: 1,
				numbers: 2,
				newdatas: null,
				pickerviewdata: [],
				pickerviewishow: false,
				pickerviewishow2: false
			};
		},

		onLoad(options) {
			this.newdatas = options.data
			// 	this.newdatas={
			//     "pid": 11,
			//     "province": "北京",
			//     "type": "2",
			//     "grade": "2",
			//     "isLoginPush": true
			// }
			this.userInfo = getApp().globalData.userInfo
			this.getAreaChildsAPI()


		},
		onShow() {
			let that = this
			uni.$once('changeHomeProvince', function(e) {
				that.province = e.provinceName
				that.diquObj = e
				that.changecolor = 2
				userManager.setProvinceInfo({
					"id": e.id,
					"province": e.provinceName
				})
			})
		},
		computed: {
			regionName() {
				// 转为字符串
				return this.region.map(item => item.name).join(' ')
			}
		},

		methods: {
			chushifuzhidiqu() {

				let cityall = this.newJsondata
				let cityArr = this.newJsondata[0].childs
				let districtArr = this.newJsondata[0].childs[0].childs
				let a1 = {
					code: cityall[0].code,
					name: cityall[0].name
				}
				let a2 = {
					code: cityArr[0].code,
					name: cityArr[0].name
				}

				let a3 = {
					code: districtArr[0].code,
					name: districtArr[0].name
				}
				this.pickerviewdata = [a1, a2, a3]
			},
			pickerviewtrue() {
				this.pickerviewishow = true
			},
			pickerviewfalse() {
				this.pickerviewishow = false
			},
			pickerviewtrue2() {
				this.pickerviewishow2 = true
			},
			pickerviewfalse2() {
				this.pickerviewishow2 = false
			},
			getpicker(data) {
				this.pickerviewdata = data
				this.schoolCode = this.pickerviewdata[2].code
				this.schoolName = '请选择您的学校'
				this.getSchoolList()

			},
			getpicker2(data) {
				this.schoolName = data
			},
			// 获取省份信息
			getAreaChildsAPI() {
				this.$request.areaChildsAPI().then(res => {
					this.newJsondata = res.data
					this.numbers = 3

					this.getNewJsonData()
				}).catch(res => {
					uni.hideToast()
				})
			},
			bindPickerChange: function(e) {
				this.index = e.detail.value
				this.schoolName = this.array[this.index]
			},
			selectdiqu() {
				uni.navigateTo({
					url: '/subpackages/subpackage2/pages/tabBar/home/shenglistsub'
				})
			},
			posi() {
				const datas = {
					's_province': this.pickerviewdata[0].name,
					's_city': this.pickerviewdata[1].name,
					's_district': this.pickerviewdata[2].name,
					's_district_numId': this.schoolCode,
					's_school': this.schoolName,
					's_class': this.banji,
				}
				this.$request.editUser(datas).then(res => {
					uni.navigateTo({
						url: '/subpackages/subpackage1/pages/score/home-score?data=' + this.newdatas
					})
				})

			},
			handleGetRegion(region) {
				this.region = region
				this.schoolCode = region[2].code
				this.schoolName = '请选择您的学校'
				this.getSchoolList()
			},
			getNewJsonData() {


				this.numbers = 3
				this.userInfoNick = this.userInfo.nick
				this.genderInput = this.userInfo.sex
				this.schoolName = this.userInfo.s_school.length > 0 ? this.userInfo.s_school : '请选择您的学校'
				this.banji = this.userInfo.s_class.length > 0 ? this.userInfo.s_class : ''

				this.pickerviewdata = [{
						name: this.userInfo.s_province ? this.userInfo.s_province : this.newJsondata[0].name
					},
					{
						name: this.userInfo.s_city ? this.userInfo.s_city : this.newJsondata[0].childs[0].name
					},
					{
						name: this.userInfo.s_district ? this.userInfo.s_district : this.newJsondata[0].childs[0]
							.childs[0].name
					},
				]
				this.schoolCode = this.userInfo.s_district_numId
				this.getSchoolList()

			},
			getSchoolList() {
				this.array = []
				if (this.schoolCode.length < 1) {
					this.$request.areaChildsAPI({
						numId: this.newJsondata[0].childs[0].childs[0].code
					}).then(res => {
						res.data.forEach(item => {
							this.array.push(item.name)
						})
						this.array.push('其他院校')
					})
				} else {

					this.$request.areaChildsAPI({
						numId: this.schoolCode
					}).then(res => {
						res.data.forEach(item => {
							this.array.push(item.name)
						})
						this.array.push('其他院校')
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.huiyuankawanshanpage {
		width: 100vw;
		min-height: 100vh;
		background: #F8F8F8;
		padding: 36rpx;
		box-sizing: border-box;

		.header {
			width: 100%;
			height: 100rpx;
			font-size: 52rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #333333;
			display: flex;
			align-items: center;
			margin-top: 150rpx
		}

		.header_sub {
			width: 100%;
			font-size: 28rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #999999;

		}

		.main {
			width: 100%;
			height: 180rpx;
			margin-top: 30rpx;

			.title {
				width: 100%;
				height: 90rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #333333;
				display: flex;
				align-items: center;
			}

			.box {
				width: 100%;
				height: 90rpx;
				background: #FFFFFF;
				padding: 24rpx 28rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;

				text {
					font-size: 28rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #999999;
				}

				image {
					width: 12rpx;
					height: 24rpx;

				}

				input {
					width: 100%;
				}

			}
		}




	}

	.filexdibu {
		position: fixed;
		bottom: 0;
		z-index: 100;
		width: 100vw;
		height: calc(120rpx + env(safe-area-inset-bottom));
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.filexdibu .buttonBox {

		width: 600rpx;
		height: 100rpx;
		background-image: url('https://mcdn.chatgk.com/xcx/static/images/midTabBar/buttonbg.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.changecolorN {
		color: #333333 !important;
	}

	.pickerContent {
		width: 400rpx;
		height: 50rpx;

	}

	.pagefixed {
		width: 100vw;
		height: 100vh;
		position: fixed;
		top: 0;
		z-index: 99999;
	}
</style>